cd "/Users/jonslapin/Dropbox/Rule of Law (EU Enlargement)/data"
*cd "/Users/jslapin/Dropbox/Rule of Law (EU Enlargement)/data"

set more off

insheet using "ilolaborsta8B.csv",clear

keep if (codecountry=="AT"|codecountry=="BE"|codecountry=="AT"|codecountry=="BG"|codecountry=="CY"|codecountry=="CZ"|codecountry=="DK"|codecountry=="EE"|codecountry=="FI"|codecountry=="FR"|codecountry=="DE"|codecountry=="GR"|codecountry=="HU"|codecountry=="IE"|codecountry=="IT"|codecountry=="LV"|codecountry=="LT"|codecountry=="LU"|codecountry=="MT"|codecountry=="PL"|codecountry=="PT"|codecountry=="RO"|codecountry=="SK"|codecountry=="SI"|codecountry=="ES"|codecountry=="SE"|codecountry=="GB")

* Keep totals for both genders
keep if codesex=="8A" 

drop if codecountry=="FR" & source_id==2

keep if subclassification=="Total"

keep if typeofdata=="Rates of fatal injuries"

collapse (mean) d1999 d2000 d2001 d2002 d2003 d2004 d2005 d2006 d2007 d2008, by(country)

egen decadeave = rowmean(d1999 d2000 d2001 d2002 d2003 d2004 d2005 d2006 d2007 d2008)

save "labfatalityrate.dta", replace

insheet using "mean unresolved infringements.csv", clear

merge 1:1 country using "labfatalityrate.dta"
drop _merge

merge 1:1 country using "eurostatpop.dta"
drop _merge 

gen dir89391 = 0
replace dir89391 = 3 if country =="Austria"
replace dir89391 = 3 if country =="France"
replace dir89391 = 4 if country =="Germany"
replace dir89391 = 1 if country =="Ireland"
replace dir89391 = 2 if country =="Italy"
replace dir89391 = 1 if country =="Luxembourg"
replace dir89391 = 1 if country =="Spain"
replace dir89391 = 1 if country =="Sweden"
replace dir89391 = 1 if country =="United Kingdom"

gen ecjyes = 0 
replace ecjyes = 1 if dir89391 >=1

gen decadeave2=decadeave^2

save "labfat.dta", replace

reg dir89391 decadeave

reg dir89391 decadeave logpop2008

reg dir89391 decadeave decadeave2

logit ecjyes decadeave
outreg2 using laborfataltable.tex, tex dec(2) 

logit ecjyes decadeave logpop2008
outreg2 using laborfataltable.tex, tex dec(2) 

estsimp logit ecjyes decadeave logpop2008

setx mean

simqi, fd(pr) changex(decadeave min max)

setx decadeave min logpop mean

simqi, pr


setx decadeave max logpop mean

simqi, pr


gen labpos = 3 
replace labpos = 12 if country=="France"
replace labpos = 4 if country=="Austria"
replace labpos = 6 if country=="United Kingdom"
replace labpos = 1 if country=="Sweden"
replace labpos = 2 if country=="Ireland"
replace labpos = 4 if country=="Luxembourg"
replace labpos = 9 if country=="Belgium"
replace labpos = 1 if country=="Denmark"
replace labpos = 11 if country=="Finland"
replace labpos = 1 if country=="Romania"
replace labpos = 12 if country=="Portugal"
replace labpos = 11 if country=="Bulgaria"
replace labpos = 9 if country=="Hungary"
replace labpos = 12 if country=="Slovenia"
replace labpos = 12 if country=="Slovakia"
replace labpos = 1 if country=="Poland"
replace labpos = 4 if country=="Latvia"
replace labpos = 4 if country=="Malta"
replace labpos = 8 if country=="Cyprus"
replace labpos = 5 if country=="Czech Republic"

twoway (scatter dir89391 decadeave, mlabel(country) mlabv(labpos) scheme(s1mono) ysc(r(-.25 4)) ytitle("European Court of Justice Cases") xtitle("Average Labor Fatality Rate per 100,000 Employees") leg(off)) (lfit dir89391 decadeave)

graph save dirfatal.gph,replace

reg aveinf decadeave logpop

cor decadeave aveinf

########################

insheet using "mean unresolved infringements.csv", clear

merge 1:1 country using "labfat.dta"
drop _merge

merge 1:1 country using "ewcs2010healthsafetyriskyes.dta"

reg dir89391 perhealthsafe

reg dir89391 perhealthsafe logpop

logit ecjyes perhealthsafe logpop
outreg2 using laborfataltable.tex, tex dec(2) 

logit ecjyes perhealthsafe logpop if (country!="Sweden"&country!="Lithuania")
outreg2 using laborfataltable.tex, tex dec(2)

logit ecjyes perhealth

logit ecjyes perhealth if (country!="Sweden"&country!="Lithuania")



gen labpos1 = 3 

replace labpos1 = 9 if country=="Austria"
replace labpos1 = 6 if country=="United Kingdom"
replace labpos1 = 9 if country=="Ireland"
replace labpos1 = 9 if country=="Netherlands"
replace labpos1 = 9 if country=="Belgium"
replace labpos1 = 1 if country=="Denmark"
replace labpos1 = 10 if country=="Finland"
replace labpos1 = 2 if country=="Romania"
replace labpos1 = 1 if country=="Portugal"
replace labpos1 = 11 if country=="Bulgaria"
replace labpos1 = 7 if country=="Hungary"
replace labpos1 = 8 if country=="Slovenia"
replace labpos1 = 12 if country=="Slovakia"
replace labpos1 = 1 if country=="Poland"
replace labpos1 = 6 if country=="Greece"
replace labpos1 = 6 if country=="Czech Republic"
replace labpos1 = 9 if country=="Malta"

twoway (scatter dir89391 perhealthsaf,  mlabel(country) mlabv(labpos1) scheme(s1mono) ysc(r(-.25 4)) ytitle("European Court of Justice Cases") xtitle("Percent Respondents Perceiving a Health Risk") leg(off)) (lfit dir89391 perhealthsaf)

graph save dirperrisk.gph,replace

reg aveinf perhealth logpop


cor perhealthsafety decadeave
scatter perhealthsafety decadeave, mlabel(country)
cor perhealthsafety decadeave if (country!="Sweden"&country!="Lithuania")

